package db2;

import beans2.Patient;
import java.sql.*;
import java.util.ArrayList;

public class PatientDao extends Connbean{
    private Connection connection=null;
    public ArrayList<Patient> getallRecord(String DoctorID) {//患者队列
        System.out.println("DoctorID:"+DoctorID);
        ArrayList<Patient>list=new ArrayList<>();
        ResultSet rs = null;
        PreparedStatement stmt = null;
        try {
            connection = getConnection();
            if (connection == null)
                System.out.println("connection error");
            //select * from YY_sign ,YY_Indent ,YY_DOCTOR_SCHEDULING,YY_patient  where YY_Sign.indid=YY_Indent .id and YY_Indent.schid=YY_DOCTOR_SCHEDULING.id and YY_sign.paccount=YY_patient.account and docid='doc002' and YY_sign.state='已签到';
            String sql = "select * from YY_sign ,YY_Indent ,YY_DOCTOR_SCHEDULING,YY_patient  where YY_Sign.indid=YY_Indent .id and YY_Indent.schid=YY_DOCTOR_SCHEDULING.id and YY_sign.pid=YY_patient.account and docid=? and YY_sign.state='已签到'";
            stmt = connection.prepareStatement(sql);
            stmt.setString(1,DoctorID);
            rs = stmt.executeQuery();
            int i=1;
            while (rs != null && rs.next()) {
                Patient patient= new Patient();
                patient.setAccount(rs.getString("Account"));
                patient.setName(rs.getString("Name"));
                patient.setIdnumber(rs.getString("Idnumber"));
                patient.setSex(rs.getString("Sex"));
                patient.setTelnumber(rs.getString("Telnumber"));
                patient.setBirthday(rs.getDate("BIRTHDATE"));
                patient.setIndid(rs.getInt("YY_indent.id"));


                patient.setOrder(rs.getInt("YY_sign.number"));
                list.add(patient);

            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

    public ArrayList<Patient> getallRecordLate(String DoctorID) {
        System.out.println("DoctorID:"+DoctorID);
        ArrayList<Patient>list=new ArrayList<>();
        ResultSet rs = null;
        PreparedStatement stmt = null;
        try {
            connection = getConnection();
            if (connection == null)
                System.out.println("connection error");
            //select * from YY_sign ,YY_Indent ,YY_DOCTOR_SCHEDULING,YY_patient  where YY_Sign.indid=YY_Indent .id and YY_Indent.schid=YY_DOCTOR_SCHEDULING.id and YY_sign.paccount=YY_patient.account and docid='doc002' and YY_sign.state='已签到';
            String sql = "select * from YY_sign ,YY_Indent ,YY_DOCTOR_SCHEDULING,YY_patient  where YY_Sign.indid=YY_Indent .id and YY_Indent.schid=YY_DOCTOR_SCHEDULING.id and YY_sign.pid=YY_patient.account and docid=? and YY_sign.state='已过号'";
            stmt = connection.prepareStatement(sql);
            stmt.setString(1,DoctorID);
            rs = stmt.executeQuery();
            int i=1;
            while (rs != null && rs.next()) {
                Patient patient= new Patient();
                patient.setOrder(i++);
                patient.setAccount(rs.getString("Account"));
                patient.setName(rs.getString("Name"));
                patient.setIdnumber(rs.getString("Idnumber"));
                patient.setSex(rs.getString("Sex"));
                patient.setTelnumber(rs.getString("Telnumber"));
                patient.setBirthday(rs.getDate("BIRTHDATE"));
                patient.setOrder(rs.getInt("YY_sign.number"));
                patient.setIndid(rs.getInt("YY_indent.id"));
                list.add(patient);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return list;
    }

}
